package WinterHomework.day05;

//一对相亲数是指：甲的约数之和等于乙，乙的等于甲，求1000以内的相亲数
public class Demo01 {
    public static void main(String[] args) {
        //利用推倒思维，现求出甲的约数和，让它等于乙再反推
        for (int i = 1; i <= 1000; i++) {
            int n = sum(i);
            if (i > n && sum(n) == i) {
                System.out.println(i + "和" + n);
            }
        }
    }

    public static int sum(int a) {
        int sum = 0;
        for (int i = 1; i <= a / 2; i++) {
            if (a % i == 0)
                sum += i;
        }
        return sum;
    }
}
